package cn.quevo.cube.provide.define.enums;

import cn.quevo.cube.provide.data.validate.impl.TimeValidate;
import cn.quevo.cube.provide.define.validate.AbstractColumnTypeValidate;
import cn.quevo.cube.provide.define.validate.impl.*;
import lombok.extern.slf4j.Slf4j;

/**
 * 字段类型编码枚举
 *
 * @author July july_sky@foxmail.com
 * @version 1.0
 * @date 2018/12/14 4:08 PM
 * @Copyright 湘豫（北京）科技有限公司版权所有.All Rights Reserved.
 */
@Slf4j
public enum ColumnTypeCode {

    DATE(DateValidate.class),
    TIME(TimeValidate.class),
    NUMERIC(NumericValidate.class),
    BIGINT(BigintValidate.class),
    TEXT(TextValidate.class),
    COLB(TextValidate.class),
    ENUM(EnumValidate.class),
    BOOLEAN(EnumValidate.class),
    AUTO_SEQUENCE(AutoSequenceValidate.class),
    DATE_SEQUENCE(DateSequenceValidate.class),
    RADIO(ChoseValidate.class), CHECKBOX(ChoseValidate.class),
    IMG_UPLOAD(ImgUploadValidate.class),
    VIDEO_UPLOAD(VideoUploadValidate.class),
    DOC_UPLOAD(DocUploadValidate.class),
    FILE_UPLOAD(FileUploadValidate.class);

    private Class validateClass;

    ColumnTypeCode(Class validateClass) {
        this.validateClass = validateClass;

    }

    public AbstractColumnTypeValidate getValidateClass() {
        try {
            return (AbstractColumnTypeValidate) this.validateClass.newInstance();
        } catch (InstantiationException e) {
            log.error("字段类型不存在", e);
        } catch (IllegalAccessException e) {
            log.error("字段类型不存在", e);
        }
        return null;
    }
}
